﻿using EFCore.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SIService;
using SService;

namespace WMSWeb.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SuppliermanagementController : ControllerBase
    {
        private readonly WmssystemContext myDb;
        private readonly SuppliermanagementS suppliermanagementS;

        public SuppliermanagementController(WmssystemContext myDb, SService.SuppliermanagementS suppliermanagementS)
        {
            this.myDb = myDb;
            this.suppliermanagementS = suppliermanagementS;
        }
        /// <summary>
        /// 查询全部
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<Su_Suppliermanagement>> Qu()
        {
            return await suppliermanagementS.Qu();
        }
        /// <summary>
        /// 根据供应商名称查询联系人和联系电话
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpGet("QuName")]
        public async Task<Su_Suppliermanagement> QuName(int Name)
        {
            return await suppliermanagementS.QuName(Name);
        }
        /// <summary>
        /// 供应商分页模糊查询
        /// </summary>
        /// <returns></returns>
        [HttpGet("FenYe")]
        public async Task<List<Su_Suppliermanagement>> FenYe(int pageSize, int currentPage, string Key = null, string Status = null, string Industry = null, string Representative = null)
        {
            return await suppliermanagementS.FenYe(pageSize, currentPage, Key, Status, Industry, Representative);
        }
        /// <summary>
        /// 供应商添加
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult<int>> Add(Su_Suppliermanagement supAdd)
        {
            // 为实体的属性赋值
            supAdd.S_MOperatorTime = DateTime.Now;
            supAdd.S_MOperator = "张三";
            supAdd.S_MIsDelete = true;

            // 调用服务层的方法执行添加操作
            return await suppliermanagementS.Add(supAdd);
        }
        /// <summary>
        /// 供应商修改
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        public async Task<ActionResult<int>> Update(Su_Suppliermanagement supUpd)
        {
            return await suppliermanagementS.Upd(supUpd);
        }
        /// <summary>
        /// 供应商逻辑删除
        /// </summary>
        /// <returns></returns>
        [HttpPut("UpdIsDelete")]
        public async Task<ActionResult<int>> UpdIsDelete(int id, bool isDeleted)
        {
            return await suppliermanagementS.UpdIsDelete(id, isDeleted);
        }
    }
}
